#pragma once

//#include <Windows.h>
#include "SPD3D11Prerequisite.h"
#include <dinput.h>

namespace SP
{
	class DLL_EXPORT SPInput
	{
	public:

		struct MouseState
		{
			LONG lAxisX;
			LONG lAxisY;
			BYTE abButtons[3];
			BYTE bPadding;       // Structure must be DWORD multiple in size.   
		};

		LONG GetX(){ return m_XToSpace; }
		LONG GetY(){ return m_YToSpace; }
		LONG GetXDelta(){ return m_XToSpace - m_LastXToSpace; }
		LONG GetYDelta(){ return m_YToSpace - m_LastYToSpace; }
		LONG GetXClient(){ return m_XToClient; }
		LONG GetYClient(){ return m_YToClient; }
		LONG GetXClientDelta(){ return m_XToClient - m_LastXToClient; }
		LONG GetYClientDelta(){ return m_YToClient - m_LastYToClient; }

		bool IsMidDown(){ return m_bIsMidDown; }
		bool IsLeftDown(){ return m_bIsLeftDown; }
		bool IsRightDown(){ return m_bIsRightDown; }

		SHORT IsKeyDown( int key )
		{
			return GetAsyncKeyState( key );
		}
		//bool WasMidDown{ return m_bWasMidDown; }
		//bool WasLeftDown{ return m_bWasLeftDown; }
		//bool WasRightDown{ return m_bWasRightDown; }
	public:
		SPInput( HWND hDlg );
		~SPInput();

		HRESULT Update();

	private:
		MouseState m_MouseState;

		LONG m_XToSpace;
		LONG m_YToSpace;

		LONG m_LastXToSpace;
		LONG m_LastYToSpace;

		LONG m_XToClient;
		LONG m_YToClient;

		LONG m_LastXToClient;
		LONG m_LastYToClient;

		//bool m_bWasMidDown;
		//bool m_bWasLeftDown;
		//bool m_bWasRightDown;
		
		bool m_bIsMidDown;
		bool m_bIsLeftDown;
		bool m_bIsRightDown;

		bool m_bInitialized;
		POINT m_pOrigin;

		HWND m_hWnd;
		LPDIRECTINPUT8          m_pDI; // DirectInput interface       
		LPDIRECTINPUTDEVICE8    m_pMouse; // Device interface
	};
}
